<div class="layuimini-main" id="DeviceReport-search">
    <style>
        .status-black {
            margin-left: 10px;
            padding-left: 5px !important;
            padding-right: 5px !important;
            color: black;
        }
    </style>
    <form class="layui-form layui-form-pane" lay-filter="DeviceReport_Detail_div_filter">

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label"> 设备SN</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid status-black" name="deviceSn" isStaus></div>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label"> 人员编号</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid status-black" name="code" isStaus></div>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label"> 姓名</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid status-black" name="name" isStaus></div>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label"> 时间</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid status-black" name="date" isStaus></div>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label"> 事件</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid status-black" name="event"></div>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label"> 体温</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid status-black" name="temp" isStaus></div>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label"> 是否通过</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid status-black" name="notePass"></div>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label"> 进出方向</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid status-black" name="enter"></div>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label"> 卡号</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid status-black" name="card"></div>
                </div>
            </div>
        </div>


        <div class="layui-form-item">

            <div class="defDivImageBox layui-panel">
                <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
                    <legend> 现场照片</legend>
                    <div class="layui-form-item " id="ReportImage">
                        <img id="showReportImg" src="/NoPIC.jpg">
                    </div>
                </fieldset>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <button type="submit" class="layui-btn layui-btn-primary" id="btnsearchclose"> <i class="layui-icon"> &#x1006;</i> 关闭</button>
            </div>
        </div>
    </form>

</div>
<script>

    layui.use(['form', 'faceAPI'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;
        var faceAPI = layui.faceAPI;
        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();
        var cardRecordEvent = [];
        cardRecordEvent["3001"] = "刷卡验证";
        cardRecordEvent["3002"] = "指纹验证";
        cardRecordEvent["3003"] = "人脸验证";
        cardRecordEvent["3004"] = "刷卡+指纹";
        cardRecordEvent["3005"] = "指纹+人脸";
        cardRecordEvent["3006"] = "刷卡+人脸";
        cardRecordEvent["3007"] = "刷卡 + 密码";
        cardRecordEvent["3008"] = "人脸 + 密码";
        cardRecordEvent["3009"] = "指纹 + 密码";
        cardRecordEvent["3010"] = "手动输入用户号加密码验证";
        cardRecordEvent["3011"] = "刷卡+指纹+密码";
        cardRecordEvent["3012"] = "刷卡+人脸+密码";
        cardRecordEvent["3013"] = "指纹+人脸+密码";
        cardRecordEvent["3014"] = "刷卡+指纹+人脸";
        cardRecordEvent["3015"] = "免验证开门";
        cardRecordEvent["3016"] = "验证通过—有效期即将过期";
        cardRecordEvent["3017"] = "使门进入常开";
        cardRecordEvent["3101"] = "未注册用户";
        cardRecordEvent["3102"] = "重复验证";
        cardRecordEvent["3103"] = "有效期未生效（还没到起始日期）";
        cardRecordEvent["3104"] = "有效期过期";
        cardRecordEvent["3105"] = "不在开门时段范围";
        cardRecordEvent["3106"] = "节假日时不能开门";
        cardRecordEvent["3107"] = "有效次数已用尽";
        cardRecordEvent["3108"] = "探测锁定";
        cardRecordEvent["3109"] = "锁定时验证，禁止开门";
        cardRecordEvent["3110"] = "挂失卡";
        cardRecordEvent["3111"] = "黑名单卡";
        cardRecordEvent["3112"] = "禁止刷卡验证  --  【权限认证方式】中禁用刷卡时";
        cardRecordEvent["3113"] = "禁止指纹验证  --  【权限认证方式】中禁用指纹时";
        cardRecordEvent["3114"] = "禁止人脸验证  --  【权限认证方式】中禁用人脸时";
        cardRecordEvent["3115"] = "设备已过期（设备有使用期限时触发，过期设备不能验证开门（需要验证五次））";
        cardRecordEvent["3116"] = "体温异常，拒绝进入";
        cardRecordEvent["3201"] = "使用按钮开门";
        cardRecordEvent["3202"] = "按钮开门时门已锁定";

        var alarmEvent = {};
        alarmEvent["1001"] = "非法认证报警";
        alarmEvent["1002"] = "门磁报警";
        alarmEvent["1003"] = "胁迫报警";
        alarmEvent["1004"] = "开门超时报警";
        alarmEvent["1005"] = "黑名单报警";
        alarmEvent["1006"] = "消防报警";
        alarmEvent["1007"] = "主机防拆报警";
        alarmEvent["1008"] = "读卡器/从机防拆报警";
        alarmEvent["1009"] = "匪警报警";
        alarmEvent["1101"] = "非法认证报警解除";
        alarmEvent["1102"] = "门磁报警解除";
        alarmEvent["1103"] = "胁迫报警解除";
        alarmEvent["1104"] = "开门超时报警解除";
        alarmEvent["1105"] = "黑名单报警解除";
        alarmEvent["1106"] = "消防报警解除";
        alarmEvent["1107"] = "防拆报警解除";
        alarmEvent["1108"] = "读卡器/从机防拆报警解除";
        alarmEvent["1109"] = "匪警报警解除";

        var systemEvent = {};
        systemEvent["2001"] = "系统加电";
        systemEvent["2002"] = "系统错误复位（看门狗）";
        systemEvent["2003"] = "设备格式化记录,恢复出厂设置（清空所有人和记录）";
        systemEvent["2004"] = "读卡器接反。";
        systemEvent["2005"] = "读卡器线路未接好。";
        systemEvent["2006"] = "无法识别的读卡器";
        systemEvent["2007"] = "网线已断开";
        systemEvent["2008"] = "网线已插入";
        systemEvent["2009"] = "WIFI已连接";
        systemEvent["2010"] = "WIFI已断开";
        systemEvent["2011"] = "主电源电压过高，大于>14V";
        systemEvent["2012"] = "主电源电压过低，小于<09V";
        systemEvent["2013"] = "主电源电压正常";
        systemEvent["2014"] = "Ups电源电压过低，小于<09V";
        systemEvent["2015"] = "Ups电源电压过高，大于>14V";
        systemEvent["2016"] = "Ups电源电压正常";
        systemEvent["2017"] = "环境温度过高温度大于>75";
        systemEvent["2018"] = "环境温度过低温度小于>-20";
        systemEvent["2019"] = "环境温度正常";
        systemEvent["2020"] = "温度传感器损坏，温度大于>100";
        systemEvent["2021"] = "软件开门";
        systemEvent["2022"] = "软件关门";
        systemEvent["2023"] = "软件常开";
        systemEvent["2024"] = "软件锁定";
        systemEvent["2025"] = "软件解除锁定";
        systemEvent["2026"] = "自动进入常开";
        systemEvent["2027"] = "自动退出常开";
        systemEvent["2028"] = "长按出门按钮常开";
        systemEvent["2029"] = "长按出门按钮常闭";
        systemEvent["2030"] = "控制器定时锁定--到时间自动锁定";
        systemEvent["2031"] = "控制器定时锁定--到时间自动解除锁定";
        systemEvent["2032"] = "报警--锁定";
        systemEvent["2033"] = "报警--解除锁定";
        systemEvent["2034"] = "进入门磁报警检测状态(布防)";
        systemEvent["2035"] = "退出门磁报警检测状态(撤防)";
        systemEvent["2036"] = "清空记录";
        systemEvent["2037"] = "读取记录";
        systemEvent["2038"] = "删除所有人员";
        systemEvent["2049"] = "更新开机图片";
        systemEvent["2050"] = "更新屏保图片";
        systemEvent["2051"] = "设备重启";

        var doorSensorEvent = {};
        doorSensorEvent["4001"] = "门磁-开门";
        doorSensorEvent["4002"] = "门磁-关门";
        doorSensorEvent["4003"] = "门未关好";
        doorSensorEvent["4004"] = "门锁-开";
        doorSensorEvent["4005"] = "门锁-关";

        var EnentTypeTable = [];
        EnentTypeTable["1"] = "正常通行(已注册或者陌生人免验证)";
        EnentTypeTable["2"] = "未注册（陌生人）";
        EnentTypeTable["3"] = "有效期已过期或未到起始时间";
        EnentTypeTable["4"] = "通行次数已用尽";
        EnentTypeTable["5"] = "不在开门时段范围";
        EnentTypeTable["6"] = "重复验证";
        EnentTypeTable["7"] = "体温异常";
        EnentTypeTable["8"] = "使用出门按钮开门";
        EnentTypeTable["9"] = "免验证开门";
        EnentTypeTable["10"] = "黑名单验证";
        EnentTypeTable["100"] = "开门超时报警";
        EnentTypeTable["101"] = "门磁报警";
        EnentTypeTable["102"] = "恢复出厂设置";
        EnentTypeTable["103"] = "删除所有人";
        EnentTypeTable["104"] = "开机";
        EnentTypeTable["106"] = "WIFI 已连接";
        EnentTypeTable["107"] = "WIFI 连接已断开";
        EnentTypeTable["108"] = "消防报警";
        EnentTypeTable["109"] = "关闭开门超时报警";
        EnentTypeTable["110"] = "关闭门磁报警";
        EnentTypeTable["111"] = "关闭消防报警";
        EnentTypeTable["112"] = "黑名单报警";
        EnentTypeTable["113"] = "关闭黑名单报警";
        EnentTypeTable["114"] = "门磁开";
        EnentTypeTable["115"] = "门磁关";

        var noteWayTitle = [];//识别介质  0:刷脸，1:打卡，2：编号+密码
        noteWayTitle[0] = "人脸识别";
        noteWayTitle[1] = "刷卡识别";
        noteWayTitle[2] = "编号+密码";

        var notePassTitle = [];
        //识别打卡是否通过 1 or 0
        notePassTitle[0] = "禁止通行";
        notePassTitle[1] = "已放行";

        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;

        if (faceAPI.DeviceReportDetail != null) {
            var report = faceAPI.DeviceReportDetail;
            //console.log(report);
            form.val("DeviceReport_Detail_div_filter", report);

            var frm = $('[lay-filter=DeviceReport_Detail_div_filter]');
            frm.find('div.status-black').each((ind, em) => {
                var _em = $(em);
                var name = _em.attr("name");
                if (report.hasOwnProperty(name))
                    _em.html(report[name]);
            });
            //console.log(frm);
            if (report.humTemp == 0) {
                frm.find('[name=temp]').html("");
            }
            else {
                frm.find('[name=temp]').html(report.temp + "℃");
            }
         //   frm.find('[name=eventType]').html(EnentTypeTable[report.event]);

            if (report.event > 1000 && report.event < 2000) {
                frm.find('[name=event]').html(alarmEvent[report.event]);
                //  frm.find('[name=notePass]').html(notePassTitle[report.notePass]);
            } else if (report.event > 2000 && report.event < 3000) {
                frm.find('[name=event]').html(systemEvent[report.event]);
            } else if (report.event > 3000 && report.event < 4000) {
                frm.find('[name=event]').html(cardRecordEvent[report.event]);
            }
            else {
                frm.find('[name=event]').html("");
                //  frm.find('[name=notePass]').html("系统事件");
            }



            if (report.card == 0) {
                frm.find('[name=cardNo]').html("");
            }



            if (report.photo != null && report.photo.length > 0) {
                $('#ReportImage').find('img').remove();
                $('#ReportImage').append('<img id="showReportImg" src="' + report.photo + '" width="240">');
                bindshowPeopleImgClick();
            }

        }

        $('#btnsearchclose').on('click', function () {
            layer.close(parentIndex);
            return false;
        });

        function bindshowPeopleImgClick() {
            $('#showReportImg').on('click', function () {
                var idBar = '#showReportImg';
                var src = $(idBar)[0].src;
                //debugger;
                var width = $(idBar).width();
                var height = $(idBar).height();
                var scaleWH = width / height;
                var bigH = 800;
                var bigW = scaleWH * bigH;
                if (bigW > 1000) {
                    bigW = 1000;
                    bigH = bigW / scaleWH;
                } // 放大预览图片
                parent.layer.open({
                    type: 1,
                    title: false,
                    closeBtn: 1,
                    shadeClose: true,
                    area: [bigW + 'px', bigH + 'px'], //宽高
                    content: '<img width="' + bigW + '" src="' + src + '" />'
                });
            });
        }

      
    });

</script>
